<template>
  <div class="header-style">
    <div class="label-text">{{currentPage}}</div>
    <div class="right-content">
      <div class="msg-icon">
        <i class="msg-icon-style iconfont" @click="returnNotification()">&#xe7a2;</i>
        <el-badge class="msg-badge" is-dot></el-badge>
      </div>
      <div class="avatar-style">
        <el-avatar :size="35" :src="imageUrl"></el-avatar>
        <el-badge
          v-if="$store.state.profile.state=='在线'"
          class="avatar-status"
          is-dot
          type="success"
        ></el-badge>
        <el-badge v-else class="avatar-status" is-dot type="danger"></el-badge>
      </div>
      <div class="avatar-name-style">
        <div class="status-style">
          <el-dropdown @command="handleCommand">
            <router-link to="/setting/profile">
              <span class="el-dropdown-link">
                客服{{nickName}}
                <i class="el-icon-arrow-down el-icon-caret-bottom"></i>
              </span>
            </router-link>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="在线">
                <i style="color:#2ed477;" class="iconfont status-icon-style">&#xec1e;</i>在线
              </el-dropdown-item>
              <el-dropdown-item command="离线">
                <i style="color:#f56c6c;" class="iconfont status-icon-style">&#xec1e;</i>离线
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import api from "@/api/api";
export default {
  name: "Header",
  components: {},
  props: {},
  data() {
    return {};
  },
  watch: {},
  computed: {
    nickName() {
      return this.$store.state.profile.nickName;
    },
    imageUrl() {
      return this.$store.state.imageUrl;
    },
    currentPage() {
      if (this.$route.path.startsWith("/index")) {
        return "首页";
      } else if (this.$route.path.startsWith("/visitor")) {
        return "访客";
      } else if (this.$route.path.startsWith("/customer/detail")) {
        return "客户详情";
      } else if (this.$route.path.startsWith("/customer")) {
        return "客户";
      } else if (this.$route.path.startsWith("/order/detail")) {
        return "工单详情";
      } else if (this.$route.path.startsWith("/order")) {
        return "工单";
      } else if (this.$route.path.startsWith("/session")) {
        return "会话";
      } else if (this.$route.path.startsWith("/statistic/workload")) {
        return "工作量统计";
      } else if (this.$route.path.startsWith("/statistic/workquality")) {
        return "工作质量统计";
      } else if (this.$route.path.startsWith("/statistic/attendance")) {
        return "考勤统计";
      } else if (this.$route.path.startsWith("/statistic/pageview")) {
        return "访问统计";
      } else if (this.$route.path.startsWith("/statistic")) {
        return "数据总览";
      } else if (this.$route.path.startsWith("/setting/profile")) {
        return "个人信息";
      } else if (this.$route.path.startsWith("/setting/announcement")) {
        return "通知公告";
      } else if (this.$route.path.startsWith("/setting/enterprise-info")) {
        return "企业信息";
      } else if (this.$route.path.startsWith("/setting/cs-management-detail")) {
        return "客服管理";
      } else if (this.$route.path.startsWith("/setting/cs-management")) {
        return "客服管理";
      } else if (this.$route.path.startsWith("/setting/group-management")) {
        return "分组管理";
      } else if (this.$route.path.startsWith("/setting/role-management")) {
        return "角色管理";
      } else if (this.$route.path.startsWith("/setting/common-word")) {
        return "常用语";
      } else if (this.$route.path.startsWith("/setting/auto-reply")) {
        return "自动回复";
      } else if (this.$route.path.startsWith("/setting/dialog-rule")) {
        return "对话规则";
      } else if (this.$route.path.startsWith("/setting/distribution-rule")) {
        return "分配规则";
      } else if (this.$route.path.startsWith("/setting/session-comment")) {
        return "会话评价";
      } else if (this.$route.path.startsWith("/setting/customer-info")) {
        return "客户信息";
      } else if (this.$route.path.startsWith("/setting/customer-tag")) {
        return "客户标签";
      } else if (this.$route.path.startsWith("/setting/blacklist")) {
        return "黑名单";
      } else if (this.$route.path.startsWith("/setting/basic-setting")) {
        return "基础设置";
      } else if (this.$route.path.startsWith("/setting/order-classification")) {
        return "工单分类";
      } else if (this.$route.path.startsWith("/setting/operation-log")) {
        return "操作日志";
      } else if (this.$route.path.startsWith("/setting/message-notification")) {
        return "消息通知";
      } else if (this.$route.path.startsWith("/setting/cs-detail")) {
        return "新增客服信息";
      } else if (this.$route.path.startsWith("/setting/role-detail")) {
        return "新增角色信息";
      } else if (this.$route.path.startsWith("/history")) {
        return "历史会话";
      }
    }
  },
  methods: {
    returnNotification() {
      this.$router.push("/setting/message-notification");
    },
    handleCommand(command) {
      api
        .partialUpdateCustomerServiceAPI({
          customerServiceId: this.$store.state.profile.customerServiceId,
          state: command
        })
        .then(res => {
          let { error, data } = res.data;
          if (error) {
            this.$message.error(data);
          } else {
            this.$store.commit("setProfileState", command);
            this.$message({
              message: "客服登录状态更新成功",
              type: "success"
            });
          }
        });
    }
  },
  created() {},
  mounted() {}
};
</script>

<style scoped>
.header-style {
  display: flex;
  justify-content: space-between;
}
.label-text {
  font-size: 20px;
  line-height: 62px;
}
.right-content {
  display: flex;
  align-items: center;
}
.msg-icon {
  padding: 0 20px;
  position: relative;
  cursor: pointer;
}
.msg-badge {
  position: absolute;
  top: 0;
  right: 15px;
}
.msg-icon-style {
  font-size: 30px;
}
.avatar-style {
  padding: 0 10px;
  position: relative;
}
.status-icon-style {
  font-size: 20px;
}
.el-dropdown-link {
  line-height: 62px;
  font-size: 13px;
}
.avatar-status {
  position: absolute;
  bottom: -5px;
  right: 5px;
}
a {
  color: #000;
  border: none;
  text-decoration: none;
}
a:hover,
a:visited,
a:link,
a:active {
  color: #000;
  text-decoration: none;
  outline: none;
}
</style>
